package com.zhouchao.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class CodeServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	response.setContentType("text/html;charset=utf-8");  
		request.setCharacterEncoding("utf-8");
		HttpSession session = request.getSession();
		 String code = (String) session.getAttribute("code");
		String codetemp = request.getParameter("codetemp");
		
		
		System.out.println("session:"+code);
        System.out.println("text"+codetemp);
		
/////////////////////////////////////////////////////////////////	
		String h=request.getRemoteHost();
        String a=request.getRemoteAddr();
     
        System.out.println("Host:"+h);
        System.out.println("Addr:"+a);
 ///////////////////////////////////////////////////////////////       
        PrintWriter out = response.getWriter(); 
        int re=0;
        
        if(codetemp.equals(code)){
        	//验证码正确
        	re=1;
        }else{
        	//验证码错误
        	re=2;
        }
        out.print(re);
        out.flush();  
        out.close(); 
        
     
}
}